<!doctype html>
<html lang="zh-CN" th:replace="admin-layout :: layout(~{::title}, ~{}, ~{::script}, ~{::body}, 'exam-list')"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <title>考试数据</title>
    <script>
        var $table = $("#table");
        var $remove = $("#removeBtn");
        var $update = $("#updateBtn");
        var $search = $("#searchBtn");
        var selections = []

        //$(this).serialize()
        $(function () {
            tableList(columns)
        })

        var columns = [{
            checkbox: true
        }, {
            field: 'loginName',
            title: '用户账号',
        }, {
            field: 'name',
            title: '用户姓名',
        }, {
            field: 'gender',
            title: '用户性别',
            formatter: genderFormatter
        }, {
            field: 'userExamStatus',
            title: '状态',
            formatter: statusFormatter
        }]

        function genderFormatter(value, row, index) {
            if (row.gender === "B") {
                return "男";
            } else if (row.gender === "C") {
                return "女";
            } else {
                return "其他";
            }
        }

        function statusFormatter(value, row, index) {
            if (value === 0) {
                return "未完成";
            } else if (value === 1) {
                return "已完成";
            }
        }

        $update.click(function () {
            location.href = "/admin/exam/data/info/" + $("#examId").val()+"/"+selections[0]
        })

        function getIdSelections() {
            return $.map($table.bootstrapTable('getSelections'), function (row) {
                return row.id
            })
        }

        $table.on('check.bs.table uncheck.bs.table ' +
            'check-all.bs.table uncheck-all.bs.table',
            function () {
                $remove.prop('disabled', !$table.bootstrapTable('getSelections').length);
                $update.prop('disabled', !$table.bootstrapTable('getSelections').length);

                // save your data, here just save the current page
                selections = getIdSelections()
                // push or splice the selections if you want to save all data selections
            })

        $search.click(function () {
            $table.bootstrapTable('refresh')
        })
    </script>
</head>
<body>
<!--<ol class="breadcrumb">
    <li><a th:href="@{/admin/exam/list}">考试列表</a></li>
    <li class="active">考试数据</li>
</ol>-->
<div class="fyl-mb10">
    <form id="toolbar">
        <input type="hidden" name="examId" th:value="${examId}" id="examId">
        <div class="row">
            <div class="col-sm-4 col-md-4 col-lg-3">
                <input type="text" class="form-control fyl-clear" name="loginName"
                       placeholder="用户账号">
            </div>
            <div class="col-sm-4 col-md-4 col-lg-3">
                <input type="text" class="form-control fyl-clear" name="name"
                       placeholder="用户姓名">
            </div>
            <div class="col-sm-4 col-md-4 col-lg-3">
                <select name="userExamStatus" class="form-control fyl-clear">
                    <option value="-1">状态</option>
                    <option value="0">未完成</option>
                    <option value="1">已完成</option>
                </select>
            </div>
            <div class="col-sm-4 col-md-4 col-lg-3">
                <a href="javascript:void(0)" class="btn btn-primary" id="searchBtn">查询</a>
                <a href="javascript:void(0)" class="btn btn-warning" id="clearSearchBtn">清空</a>
            </div>
        </div>
    </form>
</div>
<hr>
<div class="fyl-mb20">
    <button type="button" class="btn btn-primary" id="updateBtn" disabled>详情</button>
</div>
<table id="table" data-url="/admin/exam/ajax/user/list"></table>
</body>
</html>